/*jslint vars: true, forin: true, sloppy: true */
/*global probe, angular,navigator*/
probe.controller("upload", function($scope, $element, $filter, ocDialog, scriptEngine, ocAPI){
	var DI = ocDialog.queryDI($element),
		ci = DI.share,
		body
		;
	
	$scope.result = {
		name: $filter("date")(Date.now(), "yy年M月d日") + ' 对页面 ' + ci.$$config.origin + ' 的测试'
	};
	
	$scope.uploadResult = function () {
		body = {
			url: ci.$$config.origin,
			loop: ci.$$config.maxLoop,
			ua: navigator.userAgent,
			platform: navigator.platform,
			rawData: ci.$$collector.export2text(),
			sourceCode: scriptEngine.lastParse().code
		};
		ocAPI.use('uploadResult').by({
			name: $scope.result.name,
			data: angular.toJson(body)
		}).then(function (data) {
			DI.closeDialog();
		});
	};
});
